﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Epic.TakeHome.Al {
  class InvSystem {
    private Inventory _inv = new Inventory();
    private OpenFileDialog _fileDialog = new OpenFileDialog();

    public InvSystem() {
      _fileDialog.Filter = "Epic Inventory System files (*.eis)|*.eis";
    }

    public void addProduct(string name, double weight, double wholeSalePrice, int quantity) {
      Product p = new Product(name, weight, wholeSalePrice, this);
      p.Quantity = quantity;
      _inv.add(p);
    }

    public Product[] products() {
      return _inv.toArray();
    }

    public void removeProduct(Product p) {
      _inv.remove(p);
    }

    public double calculateShipping(Product p) {
      return 1 * p.Weight;
    }
    public double calculateRetail(Product p) {
      return 1 * p.Weight;
    }



    private void InvGUI_Load(object sender, EventArgs e) {

    }

    public void Load() {
      if (_fileDialog.ShowDialog() != DialogResult.OK) {
        return;
      }

      FileInfo file = new FileInfo(_fileDialog.FileName);
      FileManager fm = new FileManager(file);
      _system = new InvSystem();
      fm.Load (_system);
    }

    private void Save() {
      if (_fileDialog.ShowDialog() != DialogResult.OK) {
        return;
      }

      FileInfo file = new FileInfo(_fileDialog.FileName);
      FileManager fm = new FileManager(file);
      fm.SaveTo(_system);
    }


  }
}
